package com.sunnypower.rushfitapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.sunnypower.rushfitapp.BodyDataPart.BodyDataAdapter;
import com.sunnypower.rushfitapp.db.BodyData;

import java.util.ArrayList;
import java.util.List;

public class HistoryBodyDataActivity extends AppCompatActivity {
    private ListView history_body_list;
    private Button btn_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history_body_data);
        history_body_list = findViewById(R.id.history_body_list);
        btn_back = findViewById(R.id.btn_back);
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        List<BodyData> list = new ArrayList<>();

        List<BodyData> dataList = (ArrayList<BodyData>) getIntent().getSerializableExtra("all_data");
        BodyDataAdapter adapter = new BodyDataAdapter(HistoryBodyDataActivity.this, R.layout.body_data_part, list);
        history_body_list.setAdapter(adapter);
        if (dataList.size() == 0){
            history_body_list.setVisibility(View.GONE);
        } else {
            history_body_list.setVisibility(View.VISIBLE);
        }
        // 倒序遍历数据列表，添加活动
        list.clear();
        for (int i = (dataList.size()-1); i >= 0 ; i--) {
            list.add(dataList.get(i));
        }
        adapter.notifyDataSetChanged();
        history_body_list.setSelection(0);

    }
}
